local skel = fk.CreateSkill {
  name = "rmt__xionghao",
}

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return player.phase == Player.Play and table.contains({"basic", "trick"}, player:getMark("@rmt__xionghao"))
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local name = player:getMark("@rmt__xionghao") == "basic" and "drugs" or "fire_attack"
    local card = Fk:cloneCard(name)
    card.skillName = skel.name
    if player:canUse(card) and not player:prohibitUse(card) then
      return room:askToSkillInvoke(player, {skill_name = skel.name, prompt ="#rmt__xionghao-invoke:::"..name})
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local name = player:getMark("@rmt__xionghao") == "basic" and "drugs" or "fire_attack"
    for _ = 1, 999 do
      local card = Fk:cloneCard(name)
      card.skillName = skel.name
      if player.dead or (not player:canUse(card)) or player:prohibitUse(card) then break end
      if name == "drugs" then
        if player:isProhibited(player, card) then break end
        local use = {from = player, tos = {player}, card = card}
        room:useCard(use)
        if use.extra_data and use.extra_data.rmt__xionghaoFail then break end
      else
        local use = room:askToUseVirtualCard(player, {
          name = name, skill_name = skel.name, cancelable = false,
        })
        if not use or not use.damageDealt then break end
        room:useCard(use)
      end
    end
  end,
})

skel:addEffect(fk.CardUseFinished, {
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return data.responseToEvent
    end
  end,
  on_cost = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@rmt__xionghao", data.card:getTypeString())
    return true
  end,
  on_use = function (self, event, target, player, data)
    player.room:changeMaxHp(player, 1)
  end,
})

skel:addEffect(fk.CardRespondFinished, {
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return data.responseToEvent
    end
  end,
  on_cost = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@rmt__xionghao", data.card:getTypeString())
    return true
  end,
  on_use = function (self, event, target, player, data)
    player.room:changeMaxHp(player, 1)
  end,
})

-- 判断此【散】是否回复了体力
-- 排除防止回复体力等效果的干扰，严格判定是否真实回复体力
skel:addEffect(fk.CardUseFinished, {
  can_refresh = function (self, event, target, player, data)
    if target == player and data.card.trueName == "drugs" and table.contains(data.card.skillNames, skel.name) then
      local useEvent = player.room.logic:getCurrentEvent()
      return #useEvent:searchEvents(GameEvent.Recover, 1, function (e)
        local recover = e.data
        return recover.who == player and recover.card == data.card
      end) == 0
    end
  end,
  on_refresh = function (self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.rmt__xionghaoFail = true
  end,
})

Fk:loadTranslationTable{
  ["rmt__xionghao"] = "雄豪",
  [":rmt__xionghao"] = "你响应牌后，加1点体力上限。出牌阶段开始时，若你上次因：基本牌发动此效果，你可连续视为使用【散】直至未因此回复体力；锦囊牌发动此效果，你可连续视为使用【火攻】直至未因此造成伤害。",
  ["@@rmt__xionghao"] = "雄豪",
  ["#rmt__xionghao-invoke"] = "雄豪：你可以视为使用【%arg】",
  ["@rmt__xionghao"] = "雄豪",

  ["$rmt__xionghao1"] = "老骥伏枥，志在千里。烈士暮年，壮心不已。",
  ["$rmt__xionghao2"] = "不知我进，伯仁退？哈哈哈哈！",
}

return skel
